package com.xfcy.blog.controller.system;



import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.xfcy.blog.annotation.OperationLogger;
import com.xfcy.blog.common.R;
import com.xfcy.blog.dto.DictDataDTO;
import com.xfcy.blog.service.DictDataService;
import com.xfcy.blog.valid.AddGroup;
import com.xfcy.blog.valid.UpdateGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * (DictData)表控制层
 *
 * @author 晓风残月Lx
 * @since 2023-04-09 11:03:05
 */
@RestController
@RequestMapping("/system/dictData")
@Api(tags = "字典数据管理")
public class DictDataController {

    @Autowired
    private DictDataService dictDataService;

    @PostMapping(value = "/getDataByDictType")
    @ApiOperation(value = "根据字典类型获取字典数据", httpMethod = "POST", response = R.class, notes = "根据字典类型获取字典数据")
    public R getDataByDictType(@RequestBody List<String> types) {
        return dictDataService.getDataByDictType(types);
    }


    @GetMapping("/list")
    @SaCheckLogin
    @ApiOperation(value = "字典数据列表", httpMethod = "GET", response = R.class, notes = "字典数据列表")
    public R list(Integer pageNo, Integer pageSize, Integer dictId) {
        return dictDataService.listDictData(pageNo, pageSize, dictId);
    }

    @OperationLogger(value = "添加字典数据")
    @PostMapping("/add")
    @SaCheckPermission("/system/dictData/add")
    @ApiOperation(value = "添加字典数据", httpMethod = "POST", response = R.class, notes = "添加字典数据")
    public R add(@Validated(AddGroup.class) @RequestBody DictDataDTO dictDataDTO) {
        return dictDataService.add(dictDataDTO);
    }

    @OperationLogger(value = "修改字典数据")
    @PostMapping("/update")
    @SaCheckPermission("/system/dictData/update")
    @ApiOperation(value = "修改字典数据", httpMethod = "POST", response = R.class, notes = "批量删除字典数据")
    public R update(@Validated(UpdateGroup.class) @RequestBody DictDataDTO dictDataDTO) {
        return dictDataService.update(dictDataDTO);
    }

    @OperationLogger(value = "删除字典数据")
    @DeleteMapping("/delete")
    @SaCheckPermission("/system/dictData/delete")
    @ApiOperation(value = "删除字典数据", httpMethod = "DELETE", response = R.class, notes = "删除字典数据")
    public R delete(Long id) {
        return dictDataService.deleteDictData(id);
    }

    @OperationLogger(value = "批量删除字典数据")
    @DeleteMapping("/deleteBatch")
    @SaCheckPermission("/system/dictData/deleteBatch")
    @ApiOperation(value = "批量删除字典数据", httpMethod = "DELETE", response = R.class, notes = "批量删除字典数据")
    public R deleteBatch(@RequestBody List<Long> ids) {
        return dictDataService.deleteBatchDictData(ids);
    }


}

